package com.fjnu.dao.impl;

import com.fjnu.annotation.PerformanceMonitor;
import com.fjnu.dao.UserDao;
import com.fjnu.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * @author: 刘焰焰
 * @date: 2025/10/10
 * @description：对dao层的select及update的执行性能进行日志监控，执行时间超过3000ms或配置的timeout，要进行预警。
 */
@Repository
@Slf4j
@PerformanceMonitor
public class UserDaoImpl implements UserDao  {


    @Override
    public int insert(User user) {
        return 0;
    }

    @Override
    public int delete(String userId) {
        return 0;
    }

    @PerformanceMonitor(alarmedTime = 3000)
    @Override
    public int update(String userId, User user) {
        try {
            Thread.sleep(3400);
        } catch (Exception e) {
            log.error("update error:{}", e.getMessage()) ;
        }
        return 0;
    }

    @PerformanceMonitor(alarmedTime = 3000)
    @Override
    public User selectUserByNameAndPassword(String userId, String password) {
        try {
            Thread.sleep(3400);
        } catch (Exception e) {
            log.error("selectUserByNameAndPassword error:{}", e.getMessage()) ;
        }
        return null;
    }

    @PerformanceMonitor(alarmedTime = 3000)
    @Override
    public List<User> selectUserByRole(String roleId) {
        try {
            Thread.sleep(3400);
        } catch (Exception e) {
            log.error("selectUserByNameAndPassword error:{}", e.getMessage()) ;
        }
        return null;
    }

}
